package com.pwt.repository;

import com.pwt.repository.base.BaseRepository;
import com.pwt.entity.User;
import com.pwt.security.utils.JWTUser;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * User Repository层
 *
 * @author auto generated
 * @date 2021-08-27 15:18:32
 */
public interface UserRepository extends BaseRepository<User, String> {

    User findByUsername(String username);

    @Query("select count(1) from User where username = ?1")
    int countUserByUsername(String username);

    @Query("select rm.machineId from RoleMachine rm left join Role r on rm.roleId = r.id left join UserRole ur on r.id = ur.roleId left join User u on u.id = ur.userId where u.username = ?1")
    List<Integer> findMachinesByUsername(String userId);
}
